<template>


    <SearchTablePage :search-config="baseTableSearchModel" :table-config="baseTableModel" />

</template>

<script lang="ts" setup>
defineOptions({
    name: 'DrillExamInfoPageData',   //全局别名
    title: '表格页',   //标题
});
// 接口
import DrillExamInfoApi from '/@/api/webPath/DrillExamInfoApi.ts';


import FORM_FIELD_TYPE from '/@/constants/FormFieldType';
import VDialog from '/@/utils/dialogUtil.ts'

const router = useRouter();
const baseTable = ref(null as any);
const baseTableSearch = ref(null as any);
const editRef = ref<any>(null);

// 表格搜索初始化searchModel
const baseTableSearchModel = ref({
    columnCount: 4,
    expandLimit: 6,
    autoFit: true,
    columnWidth: '300px',
    labelPosition: 'right',
    labelWidth: '100px',
    items: [ //搜索项初始化

        // {
        //             label: "id",
        //             field: "id",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        {
            label: "关联培训",
            field: "drillId",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "考试名称",
            field: "examName",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        // {
        //             label: "考试时间（分钟）",
        //             field: "examDuration",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "考试总分（分）",
        //             field: "examTotalScore",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        {
            label: "考试类型",
            field: "examType",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        // {
        //             label: "通过分（分）",
        //             field: "passScore",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "考试开始时间",
        //             field: "startTime",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.DATE_RANGE,
        //            placeholder:"请输入",

        //         config: {
        //             props: {   //日期精度配置
        //                  type: "daterange",
        //                 startPlaceholder: "开始日期",
        //                 endPlaceholder: "结束日期",
        //                 format: "YYYY-MM-DD",
        //                   }
        //            },
        //         },

        // {
        //             label: "考试结束时间",
        //             field: "endTime",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.DATE_RANGE,
        //            placeholder:"请输入",

        //         config: {
        //             props: {   //日期精度配置
        //                  type: "daterange",
        //                 startPlaceholder: "开始日期",
        //                 endPlaceholder: "结束日期",
        //                 format: "YYYY-MM-DD",
        //                   }
        //            },
        //         },

        // {
        //             label: "单选数量",
        //             field: "singleNum",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "每题分值",
        //             field: "singleScore",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "不定项选择题数量",
        //             field: "multiNum",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "每题分值",
        //             field: "multiScore",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "判断数量",
        //             field: "judgeNum",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "每题分值",
        //             field: "judgeScore",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "创建人",
        //             field: "creator",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "修改人",
        //             field: "reviser",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "排序",
        //             field: "sort",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //             label: "创建时间",
        //             field: "create_time",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.DATE_RANGE,
        //            placeholder:"请输入",

        //         config: {
        //             props: {   //日期精度配置
        //                  type: "daterange",
        //                 startPlaceholder: "开始日期",
        //                 endPlaceholder: "结束日期",
        //                 format: "YYYY-MM-DD",
        //                   }
        //            },
        //         },

    ],

    buttons: [    //功能区域


        {
            name: "新增",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {        // 点击回调事件方法钩子，  点击触发

                VDialog.open({
                    title: '新增',

                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/drillExamInfo/edit',
                        query: {},

                    },

                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });

            },
        },
        {
            name: "导出",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {   //暴露的方法钩子
                DrillExamInfoApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle())
            }
        },
        {
            name: "批量删除",
            buttonClass: 'danger',
            width: 100,
            isShow: (row: any) => {
                return false;
            },
            click: () => {   //暴露的方法钩子
                console.log(baseTable.value.getSelection());
            },
        },
    ]
})
// 表格初始化Model
const baseTableModel = ref({
    border: true,
    pagination: true,
    inline: true,
    selectable: true,
    isFullscreen: false,
    minWidth: '200px',
    data: {    //table  初始化
        current: 1,
        size: 10,
        total: 100,
        data: []
    },
    requestData: { api: DrillExamInfoApi.getPageData, query: {} },   //数据源 参数有效性： 'steady|transient'
    columns: [
        //  {
        //   label: "id",
        //   field: "id",
        //   width:100,
        //     },
        {
            label: "启用状态",
            field: "status",
            width: 120,
            fieldFormat: "tag",
            valueMap: [
                {
                    label: "启用",
                    value: 0,
                    type: "success"
                },
                {
                    label: "禁用",
                    value: 1,
                    type: "info"
                }
            ]
        },
        {
            label: "数据来源",
            field: "sourceType",
            width: 120,
            fieldFormat: "tag",
            valueMap: [
                {
                    label: "管理端",
                    value: "0",
                    type: "info"
                },
                {
                    label: "企业端",
                    value: "1",
                    type: "success"
                }
            ]
        },
        {
            label: "考试名称",
            field: "examName",
            width: 180,
        },
        {
            label: "关联培训",
            field: "drillName",
            width: 120,
        },
        {
            label: "考试时间（分钟）",
            field: "examDuration",
            width: 180,
        },
        {
            label: "考试总分（分）",
            field: "examTotalScore",
            width: 180,
        },
        {
            label: "通过分（分）",
            field: "passScore",
            width: 180,
        },
        {
            label: "考试类型",
            field: "examTypeText",
            width: 120,
        },
        {
            label: "考试开始时间",
            field: "startTime",
            width: 200,
        },
        {
            label: "考试结束时间",
            field: "endTime",
            width: 200,
        },
        {
            label: "单选数量",
            field: "singleNum",
            width: 120,
        },
        {
            label: "每题分值",
            field: "singleScore",
            width: 150,
        },
        {
            label: "不定项选择题数量",
            field: "multiNum",
            width: 120,
        },
        {
            label: "每题分值",
            field: "multiScore",
            width: 150,
        },
        {
            label: "判断数量",
            field: "judgeNum",
            width: 120,
        },
        {
            label: "每题分值",
            field: "judgeScore",
            width: 150,
        },
        {
            label: "创建人",
            field: "creatorName",
            width: 180,
        },
        // {
        //     label: "修改人",
        //     field: "reviser",
        //     width: 180,
        // },
        //  {
        //   label: "排序",
        //   field: "sort",
        //   width:120,
        //     },
        {
            label: "创建时间",
            field: "create_time",
            width: 200,
        },
        {
            label: "更新时间",
            field: "update_time",
            width: 200,
        },
    ],


    actions: [
        {
            name: "启用",
            buttonClass: "primary",
            buttonType: "text",
            isShow: (row)=>{
                return row["status"] == 1 && row["sourceType"] == 1
            },
            click: ({row, handlers})=>{
                console.log("启用 id:",row.id)
                DrillExamInfoApi.updateStatus({
                    id: row.id,
                    status: 0,
                }).then(_=>{
                    handlers.refresh()
                })
            }
        },
        {
            name: "禁用",
            buttonClass: "danger",
            buttonType: "text",
            isShow: (row)=>{
                return row["status"] == 0 && row["sourceType"] == 1
            },
            click: ({row, handlers})=>{
                console.log("启用 id:",row.id)
                DrillExamInfoApi.updateStatus({
                    id: row.id,
                    status: 1,
                }).then(_=>{
                    handlers.refresh()
                })
            }
        },
        {
            name: "编辑考试",
            buttonClass: 'primary',   //按钮颜色控制
            buttonType: 'text',      // 按钮风格   text  link  button
            isShow: (row: any) => {  //根据业务做动态隐藏张氏
                return row["sourceType"] == 1
            },
            click: ({ row, index, handlers }) => {        // 点击回调事件方法钩子，  点击触发

                VDialog.open({
                    title: '编辑',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/drillExamInfo/edit',
                        query: { drillExamInfoId: row.id },

                    },

                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });

            },
            fixed: 'right'
        },
        {
            name: "考试二维码",

            buttonClass: 'primary',
            buttonType: 'text',
            click: async ({ row, index, handlers }) => {
                const { data } = await DrillExamInfoApi.getExamQRCode({ drillExamInfoId: row["id"] })
                console.log("data:", data)
                //router.push({name: 'CompanyInfoDetail',})
                VDialog.open({
                    title: '考试二维码',
                    dialogType: DialogType.QRCode,
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/drillExamInfo/qrcode',
                        // signin  签到 signup 报名
                        query: { link: data },
                    },

                    callBack: ({ handlers }: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            isShow: (row: object) => {
                return true;
            },
            fixed: 'right'
        },
        {
            name: "考试预览",

            buttonClass: 'primary',
            buttonType: 'text',
            click: ({ row, index, handlers }) => {

                //router.push({name: 'CompanyInfoDetail',})
                VDialog.open({
                    title: '详情',
                    dialogType: DialogType.H5,
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/drillExamInfo/preview',
                        query: { drillExamInfoId: row.id },

                    },
                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            isShow: (row: object) => {
                return true;
            },
            fixed: 'right'
        },

        // {
        //     name: "导出当前试卷",
        //     buttonClass: 'danger',
        //     buttonType: 'text',
        //     fixed: 'right',
        //     click: ({row,index,handlers}) => {

        //             $baseConfirm('您确定要删除当前项吗', null, async () => {

        //             const { message } =  await DrillExamInfoApi.del({  drillExamInfoIds: row.id })
        //                 $baseMessage(message, 'success', 'vab-hey-message-success');

        //         handlers.refresh()

        //         })

        //     }
        // },

    ]

})



onActivated(() => {
})



</script>
